package com.sdy.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.sdy.model.Employer;
import com.sdy.util.HttpUtil;

public class AccessInterceptor implements Interceptor {
	private Employer empDao = Employer.dao;
	public void intercept(ActionInvocation ai) {
		try {
			String username = (String) ai.getController().getSession().getAttribute("username");
			Employer employer = empDao.getEmployerByIpAndUserId(username, HttpUtil.getIpAddr(ai.getController().getRequest()));
			if(employer.getInt("isAdmin") == 1) {
				ai.invoke();
			} else {
				ai.getController().renderText("您无权限进行此操作");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ai.getController().redirect("/admin");
		}
		
		
		
	}

}
